package com.itshare.video.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * 日志切面
 * @Author lyr
 * @create 2020/8/20 12:39
 */
@Slf4j
// @Aspect
// @Component
public class LogAspect {
    //任何类里面的，任何参数 和 任何方法

    @Pointcut("execution(* com.itshare.video.controller.*.*(..))")
    public void printLog() {
        // log.info("args-> {}", Arrays.toString(pjp.getArgs()));
    }
    @Before("printLog()")
    public void deBefore() {

    }
    @After("printLog()")
    public void doAfter() {

    }
    @AfterReturning(value = "printLog()",returning = "result")
    public void doAfterReturn(Object result) {
        //拦截返回结果


    }

    @Around(value = "printLog()")
    public Object xxx(ProceedingJoinPoint pj) {
        try {
            log.info("args ---> {}\r\n",Arrays.toString(pj.getArgs()));
            return pj.proceed(pj.getArgs());

        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }

    }
}
